/*
 * @Description: app action
 * @Author: chenju
 * @Date: 2021-07-13 15:53:15
 * @LastEditors: qingyang
 * @LastEditTime: 2023-06-29 11:06:12
 */
import type { ActionTree } from 'vuex';
import type { AppState } from './state';
import type { RootState } from '@/store';
import { AppActionTypes } from './action-types';
import { AppMutationTypes } from './mutation-types';
import { i18n } from '@/locales';
import { getAuditRemind } from '@/apis/common/common';

export type Actions = {
  [AppActionTypes.GET_AUDIT_COUNT]({ commit }: any): void;
  [AppActionTypes.CHANGE_LANGUAGE]({ commit }: any, language: string): void;
};

export const actions: ActionTree<AppState, RootState> & Actions = {
  async [AppActionTypes.GET_AUDIT_COUNT]({ commit }: any) {
    try {
      // 获取收到请求数量接口
      const res = await getAuditRemind();
      commit(AppMutationTypes.SET_AUDIT_COUNT, res);
    } catch (error) {
      console.log('error', error);
      commit(AppMutationTypes.SET_AUDIT_COUNT, 0);
    }
  },
  [AppActionTypes.CHANGE_LANGUAGE]({ commit }: any, language: string) {
    (i18n as any).global.locale = language;
    commit(AppMutationTypes.SET_LANGUAGE, language);
  }
};
